package com.linkage.jz.bankruptcy.widget;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.Display;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.linkage.jz.bankruptcy.R;

public class VoteOverviewPromptDialog extends Dialog {


    private Activity context;
    private Button dialog_btn_negative, dialog_btn_positive;
    private String negativeStr, positiveStr;
    private View.OnClickListener mCloseListener;
    private View.OnClickListener mNegativeClickListener, mPositiveClickListener;
    public LinearLayout area_overview;


    public VoteOverviewPromptDialog(Activity context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.vote_overview_prompt_dialog);

        Window dialogWindow = this.getWindow();

        WindowManager m = context.getWindowManager();
        Display d = m.getDefaultDisplay(); // 获取屏幕宽、高用
        WindowManager.LayoutParams p = dialogWindow.getAttributes();
        p.width = (int) (d.getWidth() * 0.99);
        dialogWindow.setAttributes(p);
        dialog_btn_negative = findViewById(R.id.dialog_btn_negative);
        dialog_btn_positive = findViewById(R.id.dialog_btn_positive);

        area_overview = findViewById(R.id.area_overview);

        if (mCloseListener != null) {
            findViewById(R.id.dialog_prompt_close).setOnClickListener(mCloseListener);
        } else {
            findViewById(R.id.dialog_prompt_close).setOnClickListener(view -> dismiss());
        }


        if (!TextUtils.isEmpty(negativeStr)) {
            dialog_btn_negative.setText(negativeStr);
        }
        if (!TextUtils.isEmpty(positiveStr)) {
            dialog_btn_positive.setText(positiveStr);
        }
        if (mPositiveClickListener != null) {
            dialog_btn_positive.setOnClickListener(mPositiveClickListener);
        } else {
            dialog_btn_positive.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dismiss();
                }
            });
        }
        if (mNegativeClickListener != null) {
            dialog_btn_negative.setOnClickListener(mNegativeClickListener);
        } else {
            dialog_btn_negative.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    dismiss();
                }
            });
        }
        // 确定、取消都没有事件，那就是显示个提示信息，右上角叉掉就行了
        if (mPositiveClickListener == null && mNegativeClickListener == null) {
            findViewById(R.id.area_btn).setVisibility(View.GONE);
        }
        this.setCancelable(true);
    }

    public void setmCloseListener(View.OnClickListener clickListener) {
        this.mCloseListener = clickListener;
    }

    public void setNegativeClickListener(String text, View.OnClickListener clickListener) {
        negativeStr = text;
        mNegativeClickListener = clickListener;
    }


    public void setPositiveClickListener(String text, View.OnClickListener clickListener) {
        positiveStr = text;
        mPositiveClickListener = clickListener;
    }


}


